package si2.gui;

import jason.environment.grid.GridWorldView;
import jason.environment.grid.Location;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;

import si2.robo.Aspirador;
import si2.robo.AspiradorEnvironment;
import si2.robo.AspiradorModel;

public class AspiradorView extends GridWorldView {

	private static final long serialVersionUID = 1L;
	
	private AspiradorModel model;
	
	public AspiradorView(AspiradorModel model) {		
		super(model, "Aspirador", 600);
		this.model = model;
		defaultFont = new Font("Arial", Font.BOLD, 14); // change default font
		setVisible(true);
		repaint();
	}

	
	/** draw application objects */
	@Override
	public void draw(Graphics g, int x, int y, int object) {
		switch (object) {
		case AspiradorEnvironment.LIXO_AZUL: drawGarb(g, x, y, Color.blue);  break;
		case AspiradorEnvironment.LIXO_VERMELHO: drawGarb(g, x, y, Color.red);  break;
		case AspiradorEnvironment.LIXO_AMARELO: drawGarb(g, x, y, Color.yellow);  break;
		}
	}

	@Override
	public void drawAgent(Graphics g, int x, int y, Color c, int id) {
		String label;
		int numero;
		for(int i = 0; i < model.getAspiradores().size(); i++) {
			Aspirador aspirador = model.getAspiradores().get(i);
			numero = i + 1;
			if(aspirador.getType() == AspiradorEnvironment.LIXO_AMARELO) {
				c = Color.yellow;
				label = "ASP" + numero + " " + aspirador.getCoalitionID();
			} else if(aspirador.getType() == AspiradorEnvironment.LIXO_AZUL) {
				c = Color.blue;
				label = "ASP" + numero + " " + aspirador.getCoalitionID();
			}
			else if(aspirador.getType() == AspiradorEnvironment.LIXO_VERMELHO) {
				c = Color.red;
				label = "ASP" + numero + " " + aspirador.getCoalitionID();
			} else {
				c = Color.gray;
				label = "ASP" + numero;
			}			
			
			Location location = model.getAgPos(i);
			super.drawAgent(g, location.x, location.y, c, -1);
			g.setColor(Color.black);
			super.drawString(g, location.x, location.y, defaultFont, label);
		}
	}

	public void drawGarb(Graphics g, int x, int y, Color c) {
		super.drawObstacle(g, x, y);
		g.setColor(c);
		drawString(g, x, y, defaultFont, "G");
	}
}
